*** Settings ***
Library             Collections
Library             RequestsLibrary
Suite Setup         Create BMC Session
Suite Teardown      Delete All Sessions

*** Variables ***
${BMC_IP}           127.0.0.1
${USERNAME}         Administrator
${PASSWORD}         Admin@90000
${HTTP_PORT}        10443
${REDFISH_BASE}     https://${BMC_IP}:${HTTP_PORT}/redfish/v1

*** Test Cases ***
Redfish BMC Login Test
    [Documentation]    验证通过Redfish协议登录BMC的功能
    ${headers}=    Create Dictionary    Content-Type=application/json
    ${body}=    Create Dictionary
    ...    UserName=${USERNAME}
    ...    Password=${PASSWORD}

    ${response}=    POST    ${REDFISH_BASE}/SessionService/Sessions
    ...    headers=${headers}
    ...    json=${body}
    ...    expected_status=201
    ...    verify=${False}    # 禁用SSL证书验证（生产环境不推荐）

    # 验证关键响应要素
    Status Should Be    201    ${response}
    Should Contain X-Auth-Token    ${response.headers}
    Should Be Valid Session URI    ${response.json()}

*** Keywords ***
Should Contain X-Auth-Token
    [Arguments]    ${headers}
    Dictionary Should Contain Key    ${headers}    X-Auth-Token
    Should Not Be Empty    ${headers['X-Auth-Token']}

Should Be Valid Session URI
    [Arguments]    ${json_data}
    Dictionary Should Contain Key    ${json_data}    @odata.id
    Should Match Regexp    ${json_data['@odata.id']}  /redfish/v1/SessionService/Sessions/[a-fA-F0-9]+

Create BMC Session
    Create Session    bmc    ${REDFISH_BASE}    verify=${False} 

